package com.wxmit.starter.xfile.config;

import com.wxmit.base.util.StringUtils;
import com.wxmit.starter.xfile.core.SysFileRecorder;
import org.dromara.x.file.storage.core.recorder.FileRecorder;
import org.dromara.x.file.storage.spring.SpringFileStorageProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author huangxiong
 * @date 2024/04/10 20:53
 */
@Configuration
public class ShuShanXFileConfiguration {

    @Bean
    public FileRecorder fileRecorder(SpringFileStorageProperties properties)  {
        return new SysFileRecorder(properties);
    }

    public ShuShanXFileConfiguration(
            @Value("${ss.file.domain:}") String fileRealm,
            @Value("${ss.file.path:}") String path
    ) {
        initShushanFileConfig(fileRealm,path);
    }


    /**
     *  初始化 文件 配置信息
     * @param fileRealm 文件域名前缀
     * @param path 文件存储路径
     */
    private void initShushanFileConfig( String fileRealm, String path){
        ShushanFileConfig.domain = StringUtils.isEmpty(fileRealm) ? ShushanFileConfig.domain : fileRealm;
        ShushanFileConfig.path = StringUtils.isEmpty(path) ? ShushanFileConfig.path : path;
    }
}
